package com.yiwyn.flowdemo.BusinessNode.impl.leave;

import com.yiwyn.flowdemo.BusinessNode.BusinessHandlerRouter;
import com.yiwyn.flowdemo.domain.LeaveRecord;
import com.yiwyn.flowdemo.flow.base.FlowContext;
import com.yiwyn.flowdemo.flow.entity.BusinessHandler;
import com.yiwyn.flowdemo.service.impl.LeaveRecordServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ManagerApproveHandler extends BusinessHandler {

    @Autowired
    private LeaveRecordServiceImpl leaveRecordService;

    public ManagerApproveHandler() {
        BusinessHandlerRouter.addBusinessHandler("managerApproveHandler", this);
    }

    @Override
    public void startHandle() {
        log.info("经理开始审批");
    }

    @Override
    public FlowContext completeHandle(FlowContext flowContext) {
        String businessKey = flowContext.getBusinessKey();
        LeaveRecord leaveRecord = leaveRecordService.getById(businessKey);

        Integer leaveDay = leaveRecord.getLeaveDay();

        if (leaveDay > 3) {
            flowContext.setConclusion("N");
        } else {
            flowContext.setConclusion("Y");
        }
        return flowContext;
    }
}
